/* $Id: showdiv.js 15469 2008-12-19 06:34:44Z testyang $ */
//创建显示层
var swtemp  = 0;
var timer   = null;
var obj = null;
function update_number(object){
	obj = object;
	Ajax.call( 'flow.php?step=ajax_update_cart', object.name+"="+object.value, showdiv , 'GET', 'TEXT', true, true );
}
//显示层
function showdiv(result)
{
	var show_div_msg = "更新成功";
    
	var json = result.parseJSON();
	
    var inputid = obj.id;
    if (swtemp == 1)
    {
        hidediv("messagediv");
    }
    
    if (!getobj("messagediv"))
    {
        //若尚未创建就创建层
        crertdiv("" , "div" , "messagediv" , "messagediv");//创建层"messagediv"

        crertdiv("messagediv" , "li" , "messageli" , "messageli");//创建"请刷新"li
        getobj("messageli").innerHTML = show_div_msg;
        crertdiv("messagediv" , "a" , "messagea" , "");//创建"关闭"a
        getobj("messagea").innerHTML = show_div_exit;
        getobj("messagea").onclick = function(){hidediv("messagediv");};
    }
    var newdiv = getobj("messagediv");

    newdiv.style.left    = (getAbsoluteLeft(obj) - 20) + "px";
    newdiv.style.top     = (getAbsoluteTop(obj) - 65) + "px";
    newdiv.style.display = "block";

    if(json.tip =="number_error"){
		show_div_msg = number_error;
		getobj("goods_number_"+json.rec_id).value = json.goods_number;
    }else if(json.tip !="success"){
		show_div_msg = json.tip ;
		getobj("goods_number_"+json.rec_id).value = json.goods_number;
	}
	getobj("messageli").innerHTML = show_div_msg;
	
	if(json.total_money_tip !=null && json.total_money_tip !=""){
		getobj("total_money_tip").innerHTML = json.total_money_tip;
	}
	getobj("subtotal_"+json.rec_id).innerHTML = json.subtotal;
	getobj("price_"+json.rec_id).innerHTML = json.goodprice;
    timer = setTimeout(function(){hidediv("messagediv");} , 3000);

    swtemp  = 1;
}

//创建层
function crertdiv(parent , element , id , css)
{
    var newObj = document.createElement(element);

    if(id && id != "")
    {
        newObj.id = id;
    }
    if(css && css != "")
    {
        newObj.className = css;
    }
    if(parent && parent!="")
    {
        var theObj = getobj(parent);
        var parent = theObj.parentNode;
        if(parent.lastChild == theObj)
        {
            theObj.appendChild(newObj);
        }
        else
        {
            theObj.insertBefore(newObj, theObj.nextSibling);
        }
    }
    else
    {
        document.body.appendChild(newObj);
    }
}

//隐藏层
function hidediv(objid)
{
    getobj(objid).style.display = "none";
    swtemp = 0;
    clearTimeout(timer);
}

//获取对象
function getobj(obj)
{
    return document.getElementById(obj);
}

function getAbsoluteHeight(obj)
{
    return obj.offsetHeight;
}

function getAbsoluteWidth(obj)
{
    return obj.offsetWidth;
}

function getAbsoluteLeft(obj)
{
    var s_el = 0;
    var el   = obj;
    while(el)
    {
        s_el = s_el + el.offsetLeft;
        el   = el.offsetParent;
    }
    return s_el;
}

function getAbsoluteTop(obj)
{
    var s_el = 0;
    var el   = obj;
    while(el)
    {
        s_el = s_el + el.offsetTop;
        el   = el.offsetParent;
    }
    return s_el;
}